import request from '../request'
import type { IApiResponse } from '@/types/api'

// 教师班级信息
interface TeacherClassVO {
  id: number
  name: string
  majorId: number
  majorName: string
  collegeId: number
  collegeName: string
}

// 教师信息
interface TeacherVO {
  id: number
  username: string
  realName: string
  phone?: string
  email?: string
  avatar?: string
  userType: number
  userTypeDesc: string
  status: boolean
  createTime: string
  updateTime: string
  departmentId: number
  departmentName: string
  classes: TeacherClassVO[]
  position?: string
}

// 分页结果
interface PageResult {
  content: TeacherVO[]
  totalElements: number
  size: number
  number: number
}

// 查询参数
interface TeacherQueryParams {
  userCode?: string
  realName?: string
  phone?: string
  classIds?: string
  page?: number
  size?: number
}

// 创建/更新教师参数
interface TeacherDTO {
  userCode: string
  realName: string
  phone?: string
  email?: string
  classIds?: number[]
  position?: string
}

export const teacherApi = {
  // 分页查询教师列表
  getTeacherPage: (params: TeacherQueryParams) => {
    return request<PageResult>({
      url: '/v1/teachers/page',
      method: 'get',
      params
    })
  },

  // 创建教师
  create: (data: TeacherDTO) => {
    return request({
      url: '/v1/teachers',
      method: 'post',
      data
    })
  },

  // 获取教师详情
  getById: (id: number) => {
    return request<TeacherVO>({
      url: `/v1/teachers/${id}`,
      method: 'get'
    })
  },

  // 更新教师
  update: (id: number, data: TeacherDTO) => {
    return request({
      url: `/v1/teachers/${id}`,
      method: 'put',
      data
    })
  },

  // 获取可选班级列表
  getAvailableClasses: (majorId?: number) => {
    return request<TeacherClassVO[]>({
      url: '/v1/teachers/available-classes',
      method: 'get',
      params: { majorId }
    })
  },

  // 删除教师
  delete: (id: number) => {
    return request({
      url: `/v1/teachers/${id}`,
      method: 'delete'
    })
  },

  // 更新教师状态
  updateStatus: (id: number, status: boolean) => {
    return request({
      url: `/v1/teachers/${id}/status`,
      method: 'put',
      params: { status }
    })
  },

  // 重置教师密码
  resetPassword: (id: number) => {
    return request({
      url: `/v1/teachers/${id}/password/reset`,
      method: 'put'
    })
  }
} 